package com.product.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.product.mould.SystemMould;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 自动生成需要的字段：
 * 创建时间： 2021/3/20
 * 创建者： 王瑾
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setInsertFieldValByName("createTime",LocalDateTime.now(),metaObject);
        this.setInsertFieldValByName("createBy", SystemMould.CREATE_BY,metaObject);
        this.setUpdateFieldValByName("updateTime",LocalDateTime.now(),metaObject);
        this.setUpdateFieldValByName("updateBy",SystemMould.CREATE_BY,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setUpdateFieldValByName("updateTime",LocalDateTime.now(),metaObject);
        this.setUpdateFieldValByName("updateBy",SystemMould.CREATE_BY,metaObject);
    }
}